package cn.tiaf
package caiquan

import scala.io.StdIn
import scala.util.Random

case class Computer() extends Roller {
  def init(): Unit = {
    println("请选择对战角色(1.刘备 2.关羽 3.张飞)")
    try {
      val readInt = StdIn.readInt()
      readInt match {
        case 1 => this.name = "刘备"
        case 2 => this.name = "关羽"
        case 3 => this.name = "张飞"
        case _ =>
          println("输入有误 默认选择刘备")
          this.name = "刘备"
      }
    } catch {
      case ex: Exception =>
        println("输入有误 默认选择刘备")
        this.name = "刘备"
    }

  }

  override def showFirst(num:Int): Int = {
    val i = Random.nextInt(num)
    if(i==0)1 else i
  }
}
